<style >
.ivu-table .tableCellLeft {
  text-align: left;
}
.divItemImg {
  width: 100%;
  height: 600px;
  text-align: center;
}
.itemImg {
  max-width: 100%;
  max-height: 600px;
}

.ivu-table .demo-table-error-row td {
  background-color: #ff9900;
  color: #fff;
}
.ivu-table-cell {
  white-space: pre-line !important;
}
</style>
<template>
  <div>
    <Card ref="card">
      <p slot="title">
        机构评定详情- {{ name }} ={{ orginfo.FinalScore }} 分
        <Rate v-model="orginfo.FinalLevel" :count="5" :disabled="true" />
      </p>
      <a
        :href="printSrc"
        target="_blank"
        style="margin-right: 10px"
        slot="extra"
        >模板</a
      >
      <a
        href="#"
        style="margin-right: 10px"
        slot="extra"
        @click.prevent="PrintReport()"
        >打印</a
      >

      <Dropdown slot="extra" trigger="click" @on-click="exportDo($event)">
        <a href="javascript:void(0)">
          导出
          <Icon type="ios-arrow-down"></Icon>
        </a>
        <DropdownMenu slot="list">
          <DropdownItem name="0">所有评定项</DropdownItem>
          <DropdownItem name="1">失分项</DropdownItem>
          <DropdownItem name="2">护理型床位</DropdownItem>
          <DropdownItem name="3">服务质量检查</DropdownItem>
          <DropdownItem name="4">服务质量基本规范</DropdownItem>
          <DropdownItem name="5">养老安全基本规范</DropdownItem>
        </DropdownMenu>
      </Dropdown>

      <Tabs value="name1">
        <TabPane label="评定详情" name="name1"
          ><Table
            :row-class-name="rowClassName"
            border
            :columns="tableTitle"
            :data="tableData"
            :loading="tableLoading"
            ref="table"
            :height="tableHeight"
          ></Table
        ></TabPane>
        <TabPane label="评定结论" name="name2">
          <div>
            <Input
              v-model="finalresult.FinalResult"
              type="textarea"
              :autosize="{ minRows: 5 }"
              placeholder="请输入评定结论..."
            ></Input>
            <Button
              :loading="loadingSave"
              @click="SaveOrgFinalResult"
              style="margin-top: 10px"
              type="primary"
              >保存评定结论</Button
            >
            <Button
              :loading="loadingSave2"
              @click="SaveOrgAssessRst"
              style="margin-top: 10px; margin-left: 10px"
              type="primary"
              >重新计算评定结果</Button
            >
          </div>
        </TabPane>
        <TabPane label="护理型床位认定" name="name3"
          ><Table
            border
            :columns="tableTitleBed"
            :data="tableDataBed"
            :loading="tableLoading"
            ref="table"
            :height="tableHeight"
          ></Table
        ></TabPane>
        <TabPane label="服务质量检查" name="name4">
          <Table
            border
            :columns="tableTitleService"
            :data="tableDataService"
            :loading="tableLoading"
            ref="table"
            :height="tableHeight"
          ></Table
        ></TabPane>
        <TabPane label="服务质量基本规范" name="name5">
          <Table
            border
            :columns="tableTitleServiceBasic"
            :data="tableDataServiceBasic"
            :loading="tableLoading"
            ref="table"
            :height="tableHeight"
          ></Table
        ></TabPane>
        <TabPane label="养老安全基本规范" name="name6">
          <Table
            border
            :columns="tableTitleSafe"
            :data="tableDataSafe"
            :loading="tableLoading"
            ref="table"
            :height="tableHeight"
          ></Table
        ></TabPane>
      </Tabs>
    </Card>
    <Modal :mask-closable="false" footer-hide v-model="modalImg" width="800">
      <viewer :images="itemImgs" v-if="modalImg">
        <Carousel :height="600">
          <CarouselItem v-for="item in itemImgs" :key="item">
            <div class="divItemImg">
              <img :src="item" class="itemImg" />
            </div>
          </CarouselItem>
        </Carousel>
      </viewer>
    </Modal>
    <iframe
      id="iframe-print"
      frameborder="0"
      style="display: none"
      scrolling="auto"
      :src="printSrc"
    ></iframe>
  </div>
</template>
<script>
import excel from "@/libs/excel";
import "viewerjs/dist/viewer.css";
import Viewer from "v-viewer/src/component.vue";
import { Message, Modal } from "view-design";
import { printUrl } from "@/libs/util";
import {
  GetOrgAssess,
  GetOrgItemImg,
  GetOrgBedItemImg,
  GetOrgServiceItemImg,
  GetOrgServiceBasicItemImg,
  GetOrgSafeItemImg,
  SaveOrgFinalResult,
  SaveOrgAssessRst,
} from "@/api/org";
export default {
  name: "search_org_info",
  data() {
    return {
      printSrc: printUrl + "printorg.html?time=" + Number(new Date()),
      loadingSave: false,
      loadingSave2: false,
      tableLoading: false,
      tableHeight: 450,
      total: 0,
      pPage: 1,
      pSize: 50,
      exportLoading: false,
      groupname: "",
      isNew: false,
      modal2: false,
      modal3: false,
      modalRemark: false,
      modalImg: false,
      itemImgs: [],
      pringtTitle: "",
      orginfo: {},
      finalresult: {
        OrganizationId: "",
      },
      tableTitle: [
        {
          title: "序号",
          key: "ItemNoStr",
          align: "center",
          width: 100,
        },

        {
          title: "评定项目",
          key: "ItemName",
          align: "center",
          minWidth: 200,
          className: "tableCellLeft",
        },

        {
          title: "评定分值",
          key: "ItemMaxScore",
          align: "center",
          width: 120,
        },
        {
          title: "评定得分",
          key: "FinalScore",
          align: "center",
          width: 120,
        },
        {
          title: "扣分原因",
          key: "DeductReason",
          align: "center",
          width: 120,
        },
        {
          title: "备注",
          key: "Remark",
          align: "center",
          width: 120,
        },
        {
          title: "图片",
          align: "center",
          width: 120,
          render: (h, params) => {
            if (params.row.ItemLevelType == 4) {
              return h(
                "Button",
                {
                  props: {
                    type: "success",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                  },
                  on: {
                    click: () => {
                      this.GetOrgItemImg(params.row.Gid);
                    },
                  },
                },
                "查看"
              );
            } else {
              return null;
            }
          },
        },
      ],
      tableData: [],
      tableTitleBed: [
        {
          title: "评定内容",
          key: "ItemName",
          align: "center",
          children: [
            {
              title: "评定项目",
              key: "ItemParentType",
              align: "center",
              width: 200,
            },
            {
              title: "评定内容",
              key: "ItemParentType2",
              align: "center",
              minWidth: 200,
            },
            {
              title: "评定标准",
              key: "ItemName",
              align: "center",
              minWidth: 300,
            },
          ],
        },
        {
          title: "评定结果",
          width: 220,
          align: "center",
          children: [
            {
              title: "达标",
              align: "center",
              width: 110,
              render: (h, params) => {
                return h("span", {}, params.row.IsStandard == 1 ? "✔" : "");
              },
            },
            {
              title: "不达标",
              align: "center",
              width: 110,
              render: (h, params) => {
                return h("span", {}, params.row.IsStandard == 1 ? "" : "✔");
              },
            },
          ],
        },
        {
          title: "备注",
          key: "Remark",
          minWidth: 100,
          align: "center",
        },
        {
          title: "图片",
          align: "center",
          minWidth: 100,
          render: (h, params) => {
            return h(
              "Button",
              {
                props: {
                  type: "success",
                  size: "small",
                },
                style: {
                  marginRight: "5px",
                },
                on: {
                  click: () => {
                    this.GetOrgBedItemImg(params.row.Gid);
                  },
                },
              },
              "查看"
            );
          },
        },
      ],
      tableDataBed: [],
      tableTitleService: [
        {
          title: "评定内容",
          key: "ItemName",
          align: "center",
          minWidth: 300,
        },
        {
          title: "评定标准",
          key: "ItemParentType2",
          align: "center",
          minWidth: 200,
        },
        {
          title: "评定结果",
          width: 100,
          align: "center",
          render: (h, params) => {
            return h("span", {}, this.getFinalScoreName(params.row.FinalScore));
          },
        },
        {
          title: "备注",
          key: "Remark",
          minWidth: 100,
          align: "center",
        },
        {
          title: "图片",
          align: "center",
          minWidth: 100,
          render: (h, params) => {
            return h(
              "Button",
              {
                props: {
                  type: "success",
                  size: "small",
                },
                style: {
                  marginRight: "5px",
                },
                on: {
                  click: () => {
                    this.GetOrgServiceItemImg(params.row.Gid);
                  },
                },
              },
              "查看"
            );
          },
        },
      ],
      tableDataService: [],

      tableTitleServiceBasic: [
        {
          title: "评定项目",
          key: "ItemName",
          align: "center",
          minWidth: 300,
        },
        {
          title: "评定说明",
          key: "ItemParentType2",
          align: "center",
          minWidth: 200,
        },
        {
          title: "评定结果",
          width: 220,
          align: "center",
          children: [
            {
              title: "达标",
              align: "center",
              width: 110,
              render: (h, params) => {
                return h("span", {}, params.row.IsStandard == 1 ? "✔" : "");
              },
            },
            {
              title: "不达标",
              align: "center",
              width: 110,
              render: (h, params) => {
                return h("span", {}, params.row.IsStandard == 1 ? "" : "✔");
              },
            },
          ],
        },
        {
          title: "备注",
          key: "Remark",
          minWidth: 100,
          align: "center",
        },
        {
          title: "图片",
          align: "center",
          minWidth: 100,
          render: (h, params) => {
            return h(
              "Button",
              {
                props: {
                  type: "success",
                  size: "small",
                },
                style: {
                  marginRight: "5px",
                },
                on: {
                  click: () => {
                    this.GetOrgServiceBasicItemImg(params.row.Gid);
                  },
                },
              },
              "查看"
            );
          },
        },
      ],
      tableDataServiceBasic: [],
      tableTitleSafe: [
        {
          title: "评定项目",
          key: "ItemName",
          align: "center",
          minWidth: 300,
        },
        {
          title: "评定说明",
          key: "ItemParentType2",
          align: "center",
          minWidth: 200,
        },
        {
          title: "评定结果",
          width: 220,
          align: "center",
          children: [
            {
              title: "达标",
              align: "center",
              width: 110,
              render: (h, params) => {
                return h("span", {}, params.row.IsStandard == 1 ? "✔" : "");
              },
            },
            {
              title: "不达标",
              align: "center",
              width: 110,
              render: (h, params) => {
                return h("span", {}, params.row.IsStandard == 1 ? "" : "✔");
              },
            },
          ],
        },
        {
          title: "备注",
          key: "Remark",
          minWidth: 100,
          align: "center",
        },
        {
          title: "图片",
          align: "center",
          minWidth: 100,
          render: (h, params) => {
            return h(
              "Button",
              {
                props: {
                  type: "success",
                  size: "small",
                },
                style: {
                  marginRight: "5px",
                },
                on: {
                  click: () => {
                    this.GetOrgSafeItemImg(params.row.Gid);
                  },
                },
              },
              "查看"
            );
          },
        },
      ],
      tableDataSafe: [],
    };
  },
  props: {
    id: {
      type: String,
      required: true,
    },
    name: {
      type: String,
      required: true,
    },
  },
  components: {
    Viewer,
  },
  methods: {
    getFinalScoreName(score) {
      if (score == 1) {
        return "A";
      } else if (score == 2) {
        return "B";
      } else if (score == 3) {
        return "C";
      } else if (score == 4) {
        return "D";
      } else {
        return "";
      }
    },
    rowClassName(row, index) {
      if (row.FinalScore < row.ItemMaxScore) {
        return "demo-table-error-row";
      }
      return "";
    },
    GetOrgAssess() {
      this.tableLoading = true;
      GetOrgAssess(this.id).then((res) => {
        this.tableLoading = false;
        const data = res.data;
        if (data.Type == 1) {
          this.orginfo = data.Data;
          this.tableData = data.Data.info;
          if (this.orginfo.finalresult) {
            this.finalresult = this.orginfo.finalresult;
          }
          this.tableDataBed = this.orginfo.bedinfo.filter(
            (x) => x.IsTitle == 0
          );
          this.tableDataService = this.orginfo.serviceinfo.filter(
            (x) => x.IsTitle == 0
          );
          this.tableDataServiceBasic = this.orginfo.servicebasicinfo.filter(
            (x) => x.IsTitle == 0
          );
          this.tableDataSafe = this.orginfo.safeinfo.filter(
            (x) => x.IsTitle == 0
          );
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    SaveOrgFinalResult() {
      this.finalresult.OrganizationId = this.id;
      this.loadingSave = true;
      SaveOrgFinalResult(this.finalresult).then((res) => {
        this.loadingSave = false;
        const data = res.data;
        if (data.Type == 1) {
          this.$Message.info("保存成功");
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    SaveOrgAssessRst() {
      this.loadingSave2 = true;
      SaveOrgAssessRst(this.id).then((res) => {
        this.loadingSave2 = false;
        const data = res.data;
        if (data.Type == 1) {
          this.$Message.info("保存成功");
          this.GetOrgAssess();
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    GetOrgItemImg(id) {
      let vm = this;
      GetOrgItemImg(id).then((res) => {
        const data = res.data;
        vm.itemImgs = [];
        if (data.Type == 1) {
          if (data.Data) {
            data.Data.forEach((e) => {
              vm.itemImgs.push(e.ImgUrl);
            });
            if (vm.itemImgs.length > 0) {
              vm.modalImg = true;
            } else {
              this.$Message.success("暂无图片");
            }
          } else {
          }
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    GetOrgBedItemImg(id) {
      let vm = this;
      GetOrgBedItemImg(id).then((res) => {
        const data = res.data;
        vm.itemImgs = [];
        if (data.Type == 1) {
          if (data.Data) {
            data.Data.forEach((e) => {
              vm.itemImgs.push(e.ImgUrl);
            });
            if (vm.itemImgs.length > 0) {
              vm.modalImg = true;
            } else {
              this.$Message.success("暂无图片");
            }
          } else {
          }
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    GetOrgServiceItemImg(id) {
      let vm = this;
      GetOrgServiceItemImg(id).then((res) => {
        const data = res.data;
        vm.itemImgs = [];
        if (data.Type == 1) {
          if (data.Data) {
            data.Data.forEach((e) => {
              vm.itemImgs.push(e.ImgUrl);
            });
            if (vm.itemImgs.length > 0) {
              vm.modalImg = true;
            } else {
              this.$Message.success("暂无图片");
            }
          } else {
          }
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    GetOrgServiceBasicItemImg(id) {
      let vm = this;
      GetOrgServiceBasicItemImg(id).then((res) => {
        const data = res.data;
        vm.itemImgs = [];
        if (data.Type == 1) {
          if (data.Data) {
            data.Data.forEach((e) => {
              vm.itemImgs.push(e.ImgUrl);
            });
            if (vm.itemImgs.length > 0) {
              vm.modalImg = true;
            } else {
              this.$Message.success("暂无图片");
            }
          } else {
          }
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    GetOrgSafeItemImg(id) {
      let vm = this;
      GetOrgSafeItemImg(id).then((res) => {
        const data = res.data;
        vm.itemImgs = [];
        if (data.Type == 1) {
          if (data.Data) {
            data.Data.forEach((e) => {
              vm.itemImgs.push(e.ImgUrl);
            });
            if (vm.itemImgs.length > 0) {
              vm.modalImg = true;
            } else {
              this.$Message.success("暂无图片");
            }
          } else {
          }
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    },
    exportAll() {
      const params = {
        title: ["序号", "评定项目", "评定分值", "评定得分", "扣分原因", "备注"],
        key: [
          "ItemNoStr",
          "ItemName",
          "ItemMaxScore",
          "FinalScore",
          "DeductReason",
          "Remark",
        ],
        data: this.tableData,
        autoWidth: true,
        filename: this.name + "评定项汇总",
      };
      excel.export_org_substandard(params);
    },
    exportNotStanard() {
      const params = {
        title: ["序号", "评定项目", "评定分值", "评定得分", "扣分原因", "备注"],
        key: [
          "ItemNoStr",
          "ItemName",
          "ItemMaxScore",
          "FinalScore",
          "DeductReason",
          "Remark",
        ],
        data: this.NotStanard,
        autoWidth: true,
        filename: this.name + "失分项汇总",
      };
      excel.export_org_substandard(params);
    },
    exportBed() {
      var bedinfo = [...this.tableDataBed];
      bedinfo.forEach((e) => {
        if (e.IsStandard == 1) {
          e.IsStandard = "达标";
        } else {
          e.IsStandard = "不达标";
        }
      });

      const params = {
        title: ["序号", "评定项目", "评定内容", "评定标准", "评定结果", "备注"],
        key: [
          "ItemNoStr",
          "ItemParentType",
          "ItemParentType2",
          "ItemName",
          "IsStandard",
          "Remark",
        ],
        data: bedinfo,
        autoWidth: true,
        filename: this.name + "护理型床位认定",
      };
      excel.export_org_other(params);
    },
    exportService() {
      var serviceinfo = [...this.tableDataService];
      serviceinfo.forEach((e) => {
        if (e.FinalScore == 1) {
          e.FinalScore = "A";
        } else if (e.FinalScore == 2) {
          e.FinalScore = "B";
        } else if (e.FinalScore == 3) {
          e.FinalScore = "C";
        } else if (e.FinalScore == 4) {
          e.FinalScore = "D";
        } else {
          e.FinalScore = "";
        }
      });

      const params = {
        title: ["序号", "检查内容", "检查细则", "核查结果", "核查方式", "备注"],
        key: [
          "ItemNoStr",
          "ItemName",
          "ItemParentType2",
          "FinalScore",
          "ItemAssessDesc",
          "Remark",
        ],
        data: serviceinfo,
        autoWidth: true,
        filename: this.name + "服务质量检查",
      };
      excel.export_org_other(params);
    },
    exportServiceBasic() {
      var bedinfo = [...this.tableDataServiceBasic];
      bedinfo.forEach((e) => {
        if (e.IsStandard == 1) {
          e.IsStandard = "符合";
        } else {
          e.IsStandard = "不符合";
        }
      });

      const params = {
        title: ["序号", "检查内容", "检查要点", "检查方式", "是否符合", "备注"],
        key: [
          "ItemNoStr",
          "ItemName",
          "ItemParentType2",
          "ItemAssessDesc",
          "IsStandard",
          "Remark",
        ],
        data: bedinfo,
        autoWidth: true,
        filename: this.name + "服务质量基本规范",
      };
      excel.export_org_other(params);
    },
    exportSafe() {
      var bedinfo = [...this.tableDataSafe];
      bedinfo.forEach((e) => {
        if (e.IsStandard == 1) {
          e.IsStandard = "符合";
        } else {
          e.IsStandard = "不符合";
        }
      });

      const params = {
        title: ["序号", "检查内容", "检查要点", "检查方式", "是否符合", "备注"],
        key: [
          "ItemNoStr",
          "ItemName",
          "ItemParentType2",
          "ItemAssessDesc",
          "IsStandard",
          "Remark",
        ],
        data: bedinfo,
        autoWidth: true,
        filename: this.name + "养老安全基本规范",
      };
      excel.export_org_other(params);
    },
    PrintReport() {
      document
        .getElementById("iframe-print")
        .contentWindow.printData(this.orginfo);
    },
    exportDo(type) {
      if (type == 0) {
        this.exportAll();
      }
      if (type == 1) {
        this.exportNotStanard();
      } else if (type == 2) {
        this.exportBed();
      } else if (type == 3) {
        this.exportService();
      } else if (type == 4) {
        this.exportServiceBasic();
      } else if (type == 5) {
        this.exportSafe();
      }
    },
  },
  computed: {
    NotStanard() {
      return this.tableData.filter((x) => x.FinalScore < x.ItemMaxScore);
    },
  },
  created() {},
  mounted() {
    this.tableHeight = window.innerHeight - 260;
    this.GetOrgAssess();
  },
};
</script>
